<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #create_time="{ record }">
        {{ tool.dateFormat(record.create_time, 'yyyy-MM-dd hh:mm:ss', '-') }}
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import infoProduct from '@/api/info/infoProduct'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  infoProduct.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  infoProduct.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'info_product',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 1000
  },
  api: infoProduct.getList,
  recycleApi: infoProduct.getRecycleList,
  add: {
    show: true,
    api: infoProduct.save,
    auth: ['info:product:save']
  },
  edit: {
    show: true,
    api: infoProduct.update,
    auth: ['info:product:update']
  },
  delete: {
    show: true,
    api: infoProduct.deletes,
    auth: ['info:product:delete'],
    realApi: infoProduct.realDeletes,
    realAuth: ['info:product:realDeletes']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: "标题",
    dataIndex: "title",
    width:200,
    formType: "input",
    search: true
  },
  {
    title: "副标题",
    dataIndex: "sub_title",
    width:260,
    formType: "textarea"
  },
  {
    title: "摘要",
    dataIndex: "summary",
    width:300,
    formType: "textarea"
  },
  {
    title: "分类",
    dataIndex: "category_key",
    width:180,
    formType: "select",
    dict: {
      name: "product_category_key",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
    },
    search: true
  },
  {
    title: '标签列表',
    dataIndex: 'tag_list',
    formType: 'children-form',
    type: 'table',
    formList: [
      {
        dataIndex: 'tag', title: '标签', formType: 'input',
      }
    ],
    hide: true
  },
  {
    title: "系列",
    dataIndex: "upload_series",
    formType: "upload",
    onlyData: true,
    returnType: "url",
    multiple: false,
    chunk: false,
    type: "image"
  },

  {
    title: "图片列表",
    dataIndex: "upload_imgs",
    formType: "upload",
    onlyData: true,
    returnType: "url",
    multiple: true,
    chunk: false,
    type: "image"
  },
  {
    title: '小图说明',
    dataIndex: 'upload_tags',
    formType: 'children-form',
    type: 'table',
    formList: [
      {
        dataIndex: 'img', title: '标签',  formType: "upload",
        onlyData: true,
        returnType: "url",
        multiple: false,
        chunk: false,
        type: "image"
      },
      {
        dataIndex: 'title', title: '标签', formType: 'input',
      }
    ],
    hide: true
  },

  {
    title: "详情",
    dataIndex: "content",
    formType: "editor",
    hide: true
  },
  {
    title: "",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "create_time",
    width:180,
    formType: "range",
    search: true,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "",
    dataIndex: "update_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'info:product' } </script>